package com.baige.api.app.controller;

import com.baige.api.app.sdk.request.CardOrderConfirmRequest;
import com.baige.api.app.sdk.request.ExchangeVipCardRequest;
import com.baige.api.app.sdk.request.VipCardOrderAddRequest;
import com.baige.api.app.sdk.response.CardOrderConfirmResponse;
import com.baige.api.app.sdk.response.VipCardOrderResponse;
import com.baige.api.app.sdk.response.VipCardResponse;
import com.baige.common.core.BaseResponse;
import com.baige.common.core.MsgResponse;
import com.baige.common.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 会员卡接口
 * @author wulg
 * @date 2018/12/13.
 */
@Api(value = "VipCardController", description = "会员卡接口", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/api/rest/vip/card")
public class VipCardController
{
    private static final Logger logger = LoggerFactory.getLogger(VipCardController.class);


    /**
     * 获取会员卡列表
     * @return Result<List<VipCardResponse>>
     */
    @GetMapping(value = "/v1", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "获取会员卡列表", notes = "获取会员卡列表", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<List<VipCardResponse>> getVipCardList() {
        return null;
    }

    /**
     * 会员卡确认订单
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<CardOrderConfirmResponse>
     */

    @PostMapping(value = "/v1/confirm", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "会员卡确认订单", notes = "会员卡确认订单", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<CardOrderConfirmResponse> confirmVipCardOrder(@RequestBody @Valid CardOrderConfirmRequest requestParams, BindingResult bindingResult)
    {
        if (bindingResult.hasErrors()) {
            logger.error("会员卡确认订单参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 会员卡下单
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<VipCardOrderResponse>
     */
    @PostMapping(value = "/v1", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "会员卡下单", notes = "会员卡下单", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<VipCardOrderResponse> placeVipCardOrder(@RequestBody @Valid VipCardOrderAddRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("会员卡下单参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 兑换会员卡
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<MsgResponse>
     */
    @PostMapping(value = "/exchange", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "兑换会员卡", notes = "兑换会员卡", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<MsgResponse> exchangeVipCard(@RequestBody @Valid ExchangeVipCardRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("兑换会员卡参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }
}
